package juego

import org.uqbar.arena.windows.SimpleWindow
import model.AppModel.ExpedientesAppModel
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.List
import org.uqbar.arena.bindings.PropertyAdapter
import unq.model.Villano
import model.VillanoEditableWindow
import model.NuevoVillanoWindow

class ExpedientesWindow extends SimpleWindow<ExpedientesAppModel> {
	
	new(WindowOwner parent, ExpedientesAppModel model) {
		super(parent, model)
		title = "Expedientes"
	}
	
	override protected addActions(Panel actionsPanel) {
	new Button(actionsPanel)=> [
		caption = "cerrar expedientes"
		onClick [|close]
	]
	}
	
	override protected createFormPanel(Panel mainPanel) {
			new Panel(mainPanel) => [
			setLayout(new ColumnLayout(2)) 
			crearPanelLista(it)
			crearPanelDescripcionSelecion(it)
			crearBotonera(it)]
	}
	
		def crearBotonera(Panel panel) {
	     new Button(panel) => [caption = "Nuevo"
			onClick [ |
				modelObject.setNuevoVillano(new Villano)
				(new NuevoVillanoWindow(this, this.modelObject.nuevoVillano)).open
				modelObject.agregarVillano
		]]
		new Button(panel) => [
			caption = "Editar"
			onClick [|(new VillanoEditableWindow(this, this.modelObject.villanoSeleccionado)).open]
		]
	

	}
		def crearPanelLista(Panel panel) {
		new Panel(panel) => [
			setLayout(new VerticalLayout())
			new Label(it) => [text = "Villanos" fontSize = 13
				
			]
			new List(it) => [
				val binding = bindItemsToProperty("juego.listaVillanos")
				binding.setAdapter(new PropertyAdapter(Villano, "nombre"))
				bindValueToProperty("villanoSeleccionado")
				width = 150
				heigth = 50
			]
		]

	}
	
		def crearPanelDescripcionSelecion(Panel panel) {
		new Panel(panel) => [
			setLayout(new VerticalLayout())
			PanelDescripcion(it, "seniasParticulares", "villanoSeleccionado.seniasParticulares")
			PanelDescripcion(it, "hobbies", "villanoSeleccionado.hobbies")
		]

	}
	def PanelDescripcion(Panel panel, String textm, String propiedad) {
		new Label(panel) => [text = textm fontSize = 13]
		new List(panel) => [
			bindItemsToProperty(propiedad)
			width = 150
			heigth = 50
		]
	}
	
}